//
//  WithdrawApplyViewController.m
//  Hui
//
//  Created by HawkingWang on 16/10/31.
//  Copyright © 2016年 Hui. All rights reserved.
//

#import "WithdrawApplyViewController.h"
#import "WebViewController.h"//网页Controller

@interface WithdrawApplyViewController () <UITextFieldDelegate>
/**选择到账*/
@property (weak, nonatomic) IBOutlet UIImageView *balanceImage;
@property (weak, nonatomic) IBOutlet UIImageView *cardImage;
/**提现金额*/
@property (weak, nonatomic) IBOutlet UITextField *withdrawMoney;
/**可用余额*/
@property (weak, nonatomic) IBOutlet UILabel *usableBalance;

@end

@implementation WithdrawApplyViewController
{
    NSString *_withdraw;
    NSString *_balance;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _withdraw = @"0";
    /**余额*/
    _balance = @"754.34";
}

- (IBAction)balance:(id)sender {
    _withdraw = @"0";
    _balanceImage.image =[UIImage imageNamed:@"right-touch"];
    _cardImage.image = [UIImage imageNamed:@"right"];
}
- (IBAction)card:(id)sender {
    _withdraw = @"1";
    _balanceImage.image =[UIImage imageNamed:@"right"];
    _cardImage.image = [UIImage imageNamed:@"right-touch"];
}



/**确认提现*/
- (IBAction)confirmWithdraw:(id)sender {
    if ([_withdrawMoney.text isEqualToString:@""]) {
        [EBUtility prompt:@"请输入提现金额" with:self];
    }else if ([_withdrawMoney.text floatValue] > [_balance floatValue]) {
        [EBUtility prompt:@"提现金额不能大于可用余额" with:self];
    }else{
        [SVProgressHUD show];
        [SVProgressHUD showSuccessWithStatus:@"提现成功"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss];
            [self.navigationController popViewControllerAnimated:YES];
        });
    }
}

/**提现说明*/
- (IBAction)withdrawIntroduction:(id)sender {
    WebViewController *web = [[WebViewController alloc] init];
    web.titleStr = @"提现说明";
    [self presentViewController:web animated:YES completion:nil];
}


#pragma mark === UITextFieldDelegate ===
//- (void)textFieldDidEndEditing:(UITextField *)textField{
//    if ([textField.text floatValue] > [_balance floatValue]) {
//        [EBUtility prompt:@"提现金额不能大于可用余额" with:self];
//        [textField becomeFirstResponder];
//    }
//}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    if ([textField.text floatValue] > [_balance floatValue]) {
        [EBUtility prompt:@"提现金额不能大于可用余额" with:self];
//        [textField becomeFirstResponder];
        return NO;
    }
    [textField resignFirstResponder];
    return YES;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [_withdrawMoney resignFirstResponder];
}
- (IBAction)back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
